import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";

var _dec, _dec2, _dec3, _dec4, _class, _class2;

/**
 * 接口字段权限维护 /ciam/sub-account-org/api/:usedId/:permissionId
 * EditFormModal
 * @date 2019-07-10
 */
import React, { Component } from 'react';
import { Col, Form, Input, Modal, Row, Select } from 'antd';
import { Bind } from 'lodash-decorators';
import Lov from 'components/Lov';
import intl from 'utils/intl';
import { MODAL_FORM_ITEM_LAYOUT } from 'utils/constants';
var EditFormModal = (_dec = Form.create({
  fieldNameProp: null
}), _dec2 = Bind(), _dec3 = Bind(), _dec4 = Bind(), _dec(_class = (_class2 = /*#__PURE__*/function (_Component) {
  _inherits(EditFormModal, _Component);

  var _super = _createSuper(EditFormModal);

  function EditFormModal() {
    _classCallCheck(this, EditFormModal);

    return _super.apply(this, arguments);
  }

  _createClass(EditFormModal, [{
    key: "handleOk",
    value: // Modal
    function handleOk() {
      var _this = this;

      var form = this.props.form;
      form.validateFields(function (err, data) {
        if (!err) {
          var onOk = _this.props.onOk;
          onOk(data);
        }
      });
    }
  }, {
    key: "handleCancel",
    value: function handleCancel() {
      var onCancel = this.props.onCancel;
      onCancel();
    } // field change

    /**
     * 字段改变后 修改字段类型
     * @param {FIELD} field
     */

  }, {
    key: "handleFieldChange",
    value: function handleFieldChange(_, field) {
      var form = this.props.form;
      form.setFieldsValue({
        fieldType: field.fieldType
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props = this.props,
          _this$props$isCreate = _this$props.isCreate,
          isCreate = _this$props$isCreate === void 0 ? true : _this$props$isCreate,
          _this$props$visible = _this$props.visible,
          visible = _this$props$visible === void 0 ? false : _this$props$visible,
          _this$props$loading = _this$props.loading,
          loading = _this$props$loading === void 0 ? false : _this$props$loading,
          form = _this$props.form,
          _this$props$record = _this$props.record,
          record = _this$props$record === void 0 ? {} : _this$props$record,
          _this$props$fieldType = _this$props.fieldType,
          fieldType = _this$props$fieldType === void 0 ? [] : _this$props$fieldType,
          _this$props$permissio = _this$props.permissionRule,
          permissionRule = _this$props$permissio === void 0 ? [] : _this$props$permissio,
          dimensionValue = _this$props.dimensionValue,
          permissionDimension = _this$props.permissionDimension,
          permissionId = _this$props.permissionId,
          organizationId = _this$props.organizationId;
      var title = isCreate ? intl.get('ciam.subAccount.view.title.fieldPermissionCreate').d('字段权限新建') : intl.get('ciam.subAccount.view.title.fieldPermissionEdit').d('字段权限编辑');
      return /*#__PURE__*/React.createElement(Modal, {
        destroyOnClose: true,
        title: title,
        visible: visible,
        wrapClassName: "ant-modal-sidebar-right",
        transitionName: "move-right",
        onCancel: this.handleCancel,
        onOk: this.handleOk,
        confirmLoading: loading
      }, /*#__PURE__*/React.createElement(Form, null, /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, null, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, MODAL_FORM_ITEM_LAYOUT, {
        label: intl.get('ciam.subAccount.model.fieldPermission.fieldName').d('字段名称')
      }), form.getFieldDecorator('fieldId', {
        initialValue: record.fieldId,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('ciam.subAccount.model.fieldPermission.fieldName').d('字段名称')
          })
        }]
      })( /*#__PURE__*/React.createElement(Lov, {
        queryParams: {
          dimensionValue: dimensionValue,
          permissionDimension: permissionDimension,
          permissionId: permissionId,
          organizationId: organizationId
        },
        code: "CIAM.FIELD.PERMISSION",
        disabled: !isCreate,
        textValue: record.fieldDescription,
        onChange: this.handleFieldChange
      })))), /*#__PURE__*/React.createElement(Col, null, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, MODAL_FORM_ITEM_LAYOUT, {
        label: intl.get('ciam.subAccount.model.fieldPermission.fieldType').d('字段类型')
      }), form.getFieldDecorator('fieldType', {
        initialValue: record.fieldType,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('ciam.subAccount.model.fieldPermission.fieldType').d('字段类型')
          })
        }]
      })( /*#__PURE__*/React.createElement(Select, {
        disabled: true
      }, fieldType.map(function (item) {
        return /*#__PURE__*/React.createElement(Select.Option, {
          key: item.value,
          value: item.value
        }, item.meaning);
      }))))), /*#__PURE__*/React.createElement(Col, null, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, MODAL_FORM_ITEM_LAYOUT, {
        label: intl.get('ciam.subAccount.model.fieldPermission.rule').d('权限规则')
      }), form.getFieldDecorator('permissionType', {
        initialValue: record.permissionType,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('ciam.subAccount.model.fieldPermission.rule').d('权限规则')
          })
        }]
      })( /*#__PURE__*/React.createElement(Select, null, permissionRule.map(function (item) {
        return /*#__PURE__*/React.createElement(Select.Option, {
          key: item.value,
          value: item.value
        }, item.meaning);
      }))))), form.getFieldValue('permissionType') === 'DESENSITIZE' && /*#__PURE__*/React.createElement(Col, null, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, MODAL_FORM_ITEM_LAYOUT, {
        label: intl.get('ciam.subAccount.model.fieldPermission.desensitize').d('脱敏规则')
      }), form.getFieldDecorator('permissionRule', {
        initialValue: record.permissionRule,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('ciam.subAccount.model.fieldPermission.desensitize').d('脱敏规则')
          })
        }, {
          max: 60,
          message: intl.get('cpaas.common.validation.max', {
            max: 60
          })
        }]
      })( /*#__PURE__*/React.createElement(Input, null)))))));
    }
  }]);

  return EditFormModal;
}(Component), (_applyDecoratedDescriptor(_class2.prototype, "handleOk", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "handleOk"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleCancel", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "handleCancel"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleFieldChange", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "handleFieldChange"), _class2.prototype)), _class2)) || _class);
export { EditFormModal as default };